import { type } from "os"

function add(x: number, y: number): number {
    return x + y
}
var add1: (x: number, y: number) => number = function add(x, y) {
    return x + y
}
var add2: (x: number, y: number) => number = (x, y) => x + y

interface AddInterFace {
    (x: number, y: number): number
}

var add3: AddInterFace = (x, y) => x + y
var add2: { (x: number, y: number): number } = (x, y) => x + y



// 函数的重载：根据不同的参数，返回不同的类型
function reverse(target: number | string) {
    if (typeof target === 'number') {
        return +[...target.toString()].reverse().join('')
    }
    if (typeof target === 'string') {
        return target.split("").reverse().join('')
    }
}
console.log(reverse('js++'));
console.log(reverse(12345));


